/*
https://leetcode.cn/problems/pizza-with-3n-slices/solution/3n-kuai-pi-sa-by-leetcode-solution/
 */
public class Solution1388 {
    public int maxSizeSlices(int[] slices) {
        int[] a=new int[slices.length-1];
        System.arraycopy(slices,1,a,0,slices.length-1);
        int[] b=new int[slices.length-1];
        System.arraycopy(slices,0,b,0,slices.length-1);
        return Math.max(calculate(a),calculate(b));
    }

    private int calculate(int[] a) {
        int[][] f=new int[a.length+1][(a.length+1)/3+1];
        for (int i=1;i<=a.length;i++){
            for (int j=1;j<f[0].length;j++){
                f[i][j]=Math.max(f[i-1][j],(i-2>=0?f[i-2][j-1]:0)+a[i-1]);
            }
        }
        return f[a.length][f[0].length-1];
    }

    public static void main(String[] args) {
        System.out.println(new Solution1388().maxSizeSlices(new int[]{1,2,3,4,5,6}));
    }
}
